package tool

import java.io.File
import java.nio.file.Files

import dao.ModeDao
import utils.Utils

/**
 * Created by yz on 9/5/2020
 */
object Tool {

  val dbName="protein_database"
  val playPath = new File("../").getAbsolutePath
  val windowsPath = s"C:\\${dbName}"
  val isWindows = {
    if (new File(windowsPath).exists()) true else false
  }
  val linuxPath = playPath + s"/${dbName}"
  val path = {
    if (new File(windowsPath).exists()) windowsPath else linuxPath
  }
  val dataDir = new File(path, "data")

  val binPath = new File(path, "bin")
  val anno = new File(binPath, "Anno")
  val blastFile = new File(binPath, "ncbi-blast-2.6.0+/bin/blastn")
  val blastpFile = new File(binPath, "ncbi-blast-2.6.0+/bin/blastp")
  val blastxFile = new File(binPath, "ncbi-blast-2.6.0+/bin/blastx")
  val blast2HtmlFile = new File(binPath, "blast2html-82b8c9722996/blast2html.py")
  val rPath = {
    val rPath = "C:\\workspaceForIDEA\\protein\\rScripts"
    val linuxRPath = linuxPath + "/rScripts"
    if (new File(rPath).exists()) rPath else linuxRPath
  }
  val windowsTestDir = new File("C:\\temp")
  val linuxTestDir = new File(playPath, "workspace")
  val testDir = if (windowsTestDir.exists()) windowsTestDir else linuxTestDir
  val pyPath = {
    val path = "C:\\workspaceForIDEA\\vg_protein\\pyScripts"
    val linuxPyPath = linuxPath + "/pyScripts"
    if (new File(path).exists()) path else linuxPyPath
  }

  def isTestMode(implicit modeDao: ModeDao) = {
    val mode = Utils.execFuture(modeDao.select)
    if (mode.test == "t") true else false
  }

  def createTempDirectory(prefix: String)(implicit modeDao: ModeDao) = {
    if (isTestMode) Tool.testDir else Files.createTempDirectory(prefix).toFile
  }

  def deleteDirectory(direcotry: File)(implicit modeDao: ModeDao) = {
    if (!isTestMode) Utils.deleteDirectory(direcotry)
  }

}
